package com.ysd.service.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ysd.service.dao.UserDao;
import com.ysd.service.dao.VersionDao;
import com.ysd.service.dto.UserDto;
import com.ysd.service.entity.User;
import com.ysd.service.entity.Version;
import com.ysd.service.util.IBeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class VersionService extends ServiceImpl<VersionDao, Version> {

    @Autowired
    private VersionDao versionDao;

    /**
     * 查询最新版本信息
     * @return
     */
    public Version getCurrentVersion(){
        LambdaQueryWrapper<Version> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Version::getDelFlag, 0);
        queryWrapper.orderByDesc(Version::getVersion);
        queryWrapper.last("LIMIT 1"); // 限制结果数量为1条
        return versionDao.selectOne(queryWrapper);
    }

    /**
     * insert   添加版本
     * @param param
     */
    public void addVersion(Version param){
        versionDao.insert(param);
    }

    /**
     * update   编辑版本
     * @param param
     */
    public void editorVersion(Version param){
        LambdaUpdateWrapper<Version> updateWrapper = Wrappers.lambdaUpdate();
        updateWrapper.eq(Version::getVersion, param.getVersion());
        updateWrapper.set(Version::getRemarks, param.getRemarks());
        versionDao.update(param, updateWrapper);
    }

    /**
     * delete   删除版本
     * @param id
     */
    public void delVersion(String id){
        versionDao.deleteById(id);
    }



}
